package org.csu.mall.service.impl;

import com.alipay.demo.trade.model.TradeStatus;
import com.alipay.demo.trade.model.result.AlipayF2FPrecreateResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import org.apache.commons.lang3.StringUtils;
import org.csu.mall.common.CONSTANT;
import org.csu.mall.common.ResponseCode;
import org.csu.mall.common.UniformResponse;
import org.csu.mall.entity.*;
import org.csu.mall.persistence.*;
import org.csu.mall.service.ICustomerOrderService;
import org.csu.mall.util.AlipayUtil;
import org.csu.mall.util.CodeUtil;
import org.csu.mall.util.DateUtil;
import org.csu.mall.util.PropertiesUtil;
import org.csu.mall.vo.AlipayVO;
import org.csu.mall.vo.CustomerOrderListVO;
import org.csu.mall.vo.CustomerOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;
import java.util.List;


@Service("customerOrderService")
public class ICustomerOrderServiceImpl implements ICustomerOrderService {

    @Autowired
    private CorderMapper corderMapper;

    @Autowired
    private MerchantOrderMapper merchantOrderMapper;

    @Autowired
    private CommodityMapper commodityMapper;

    @Autowired
    private AccountMapper accountMapper;

    @Autowired
    private CommodityRateMapper commodityRateMapper;

    //生成顾客购物订单，但但订单状态为未支付，若订单选择货到付款，要等发货人确定才发货；若选择线上支付，则付款后发货
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<CustomerOrderVO> purchaseOrder(CustomerOrder customerOrder, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        if(StringUtils.isBlank(customerOrder.getCAddress())){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ADDRESS_NEEDED.getCode(), ResponseCode.ADDRESS_NEEDED.getDescription());
        }

        //查询并设置发货商id
        MerchantOrder merchantOrder = merchantOrderMapper.selectOne(
                Wrappers.<MerchantOrder>query().eq("item_id", customerOrder.getItemId()));
        if(merchantOrder == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.COMMODITY_NOT_EXIST.getCode(), ResponseCode.COMMODITY_NOT_EXIST.getDescription());
        }
        customerOrder.setMerchantId(merchantOrder.getMerchantId());
        customerOrder.setMAddress(merchantOrder.getAddress());
        customerOrder.setMPhone(merchantOrder.getPhoneNumber());
        //检测库存
        int stock = commodityMapper.selectOne(
                Wrappers.<Commodity>query().select("stock").eq("item_id", customerOrder.getItemId())).getStock();
        if(stock < customerOrder.getItemNumber()){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.STOCK_NOT_ENOUGH.getCode(), ResponseCode.STOCK_NOT_ENOUGH.getDescription());
        }

        customerOrder.setOrderId(CodeUtil.createOrderId());
        customerOrder.setOrderName(customerOrder.getItemName());
        customerOrder.setTotalPrice(customerOrder.getUnitPrice() * customerOrder.getItemNumber());
        customerOrder.setUserId(account.getUserId());
        //设置商品信息
        Commodity commodity = commodityMapper.selectOne(Wrappers.<Commodity>query().eq("item_id", customerOrder.getItemId()));
        customerOrder.setItemName(commodity.getItemName());
        customerOrder.setUnitPrice(commodity.getPrice());
        customerOrder.setOrderSource(commodity.getSource());
        customerOrder.setDeliveryStatus(CONSTANT.CustomerOrderStatus.ORDER_NOT_DELIVERY.getCode());


        customerOrder.setOrderState(CONSTANT.CustomerOrderStatus.UNPAID.getCode());
        customerOrder.setCreateTime(LocalDateTime.now());
        customerOrder.setUpdateTime(LocalDateTime.now());
        CustomerOrderVO customerOrderVO = this.entityToVO(customerOrder);
        int row = corderMapper.insert(customerOrder);
        if(row > 0){
            return UniformResponse.createForSuccess(ResponseCode.SUCCESS.getDescription(), customerOrderVO);
        }
        return UniformResponse.createForErrorCodeMessage(
                ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDescription());
    }

    //订单支付，若库存足够直接发货，库存不足，则等待发货
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<String> orderPayment(Long orderId, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        CustomerOrder customerOrder = corderMapper.selectOne(
                Wrappers.<CustomerOrder>query().eq("order_id", orderId).eq("order_state", CONSTANT.CustomerOrderStatus.UNPAID.getCode()));
        if(customerOrder == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.CUSTOMER_ORDER_NOT_EXIST.getCode(), ResponseCode.CUSTOMER_ORDER_NOT_EXIST.getDescription());
        }
        if(account.getBalance() < customerOrder.getTotalPrice()){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.BALANCE_NOT_ENOUGH.getCode(), ResponseCode.BALANCE_NOT_ENOUGH.getDescription());
        }
        Commodity commodity = commodityMapper.selectOne(Wrappers.<Commodity>query().eq("item_id", customerOrder.getItemId()));
        int restStock = commodity.getStock() - customerOrder.getItemNumber();

        //更新商品状态
        if(restStock < 0){
            customerOrder.setDeliveryStatus(CONSTANT.CustomerOrderStatus.ORDER_NOT_DELIVERY.getCode());
        }else if(restStock == 0){
            customerOrder.setDeliveryStatus(CONSTANT.CustomerOrderStatus.ORDER_DELIVERY.getCode());
            MerchantOrder merchantOrder = merchantOrderMapper.selectOne(
                    Wrappers.<MerchantOrder>query().eq("item_id", commodity.getItemId()));
            merchantOrder.setOrderState(CONSTANT.MerchantOrderStatus.ORDER_OUT_SALE.getCode());
            if(commodity.getSource() == CONSTANT.CommoditySource.PERSONAL_SALE.getCode()){
                commodityMapper.delete(
                        Wrappers.<Commodity>query().eq("item_id", commodity.getItemId()));
            }
            if(commodity.getSource() == CONSTANT.CommoditySource.OFFICIAL_SALE.getCode()){
                commodity.setStock(restStock);
                commodity.setStatus(CONSTANT.CommodityStatus.OUT_SALE.getCode());
                commodity.setUpdateTime(LocalDateTime.now());
                commodityMapper.updateById(commodity);
            }
            merchantOrderMapper.updateById(merchantOrder);
        }else {
            customerOrder.setDeliveryStatus(CONSTANT.CustomerOrderStatus.ORDER_DELIVERY.getCode());
            commodity.setStock(restStock);
            commodity.setUpdateTime(LocalDateTime.now());
            commodityMapper.updateById(commodity);
        }

        //更新用户余额
        Account newAccount= new Account();
        newAccount.setUserId(account.getUserId());
        newAccount.setBalance(account.getBalance() - customerOrder.getTotalPrice());
        newAccount.setUpdateTime(LocalDateTime.now());
        accountMapper.updateById(newAccount);
        //更新订单状态
        customerOrder.setOrderState(CONSTANT.CustomerOrderStatus.PAID_UNCONFIRMED.getCode());
        customerOrder.setUpdateTime(LocalDateTime.now());
        corderMapper.updateById(customerOrder);
        return UniformResponse.createForSuccessMessage(ResponseCode.SUCCESS.getDescription());
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<String> orderConfirm(Long orderId, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        CustomerOrder customerOrder = corderMapper.selectOne(Wrappers.<CustomerOrder>query().eq("order_id", orderId));
        if(customerOrder == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ILLEGAL_ARGUMENT.getCode(), ResponseCode.ILLEGAL_ARGUMENT.getDescription());
        }
        customerOrder.setOrderState(CONSTANT.CustomerOrderStatus.CONFIRM_NO_EVALUATION.getCode());
        customerOrder.setUpdateTime(LocalDateTime.now());
        int row = corderMapper.updateById(customerOrder);
        if(row > 0) {
            return UniformResponse.createForSuccessMessage(ResponseCode.SUCCESS.getDescription());
        }
        return UniformResponse.createForErrorCodeMessage(
                ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDescription());
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<String> orderComment(Long orderId, String comment, Integer star, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        CustomerOrder customerOrder = corderMapper.selectById(orderId);
        if(customerOrder == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ORDER_NOT_EXIST.getCode(), ResponseCode.ORDER_NOT_EXIST.getDescription());
        }
        customerOrder.setOrderReview(comment);
        customerOrder.setOrderStar(star);
        customerOrder.setOrderState(CONSTANT.CustomerOrderStatus.EVALUATION_ORDER.getCode());
        customerOrder.setUpdateTime(LocalDateTime.now());
        corderMapper.updateById(customerOrder);
        CommodityRate commodityRate = new CommodityRate();
        commodityRate.setItemId(customerOrder.getItemId());
        commodityRate.setItemName(customerOrder.getItemName());
        commodityRate.setItemStar(customerOrder.getOrderStar());
        commodityRate.setComment(comment);
        commodityRate.setUserId(account.getUserId());
        commodityRate.setCreateTime(LocalDateTime.now());
        commodityRate.setUpdateTime(LocalDateTime.now());
        commodityRateMapper.insert(commodityRate);
        return UniformResponse.createForSuccessMessage("订单评价成功");
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<String> orderDelivery(Long orderId, Account account) {

        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }

        CustomerOrder customerOrder = corderMapper.selectById(orderId);

        if(customerOrder == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ILLEGAL_ARGUMENT.getCode(), ResponseCode.ILLEGAL_ARGUMENT.getDescription());
        }
        Commodity commodity = commodityMapper.selectOne(
                Wrappers.<Commodity>query().eq("item_id", customerOrder.getItemId()));
        if(commodity == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.COMMODITY_NOT_EXIST.getCode(), ResponseCode.COMMODITY_NOT_EXIST.getDescription());
        }

        //更新商品信息
        if(commodity.getStock() < customerOrder.getItemNumber()){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.STOCK_NOT_ENOUGH.getCode(), ResponseCode.STOCK_NOT_ENOUGH.getDescription());
        }else if(commodity.getStock() == customerOrder.getItemNumber()){
            MerchantOrder merchantOrder = merchantOrderMapper.selectOne(Wrappers.<MerchantOrder>query().eq("item_id", commodity.getItemId()));
            merchantOrder.setOrderState(CONSTANT.MerchantOrderStatus.ORDER_OUT_SALE.getCode());
            if(commodity.getSource() == CONSTANT.CommoditySource.PERSONAL_SALE.getCode()){
                commodityMapper.delete(
                        Wrappers.<Commodity>query().eq("item_id", commodity.getItemId()));
            }
            if(commodity.getSource() == CONSTANT.CommoditySource.OFFICIAL_SALE.getCode()){
                commodity.setStock(0);
                commodity.setStatus(CONSTANT.CommodityStatus.OUT_SALE.getCode());
                commodity.setUpdateTime(LocalDateTime.now());
                commodityMapper.updateById(commodity);
            }
            merchantOrder.setUpdateTime(LocalDateTime.now());
            merchantOrderMapper.updateById(merchantOrder);
        }else{
            commodity.setStock(commodity.getStock() - customerOrder.getItemNumber());
            commodity.setUpdateTime(LocalDateTime.now());
            commodityMapper.updateById(commodity);
        }

        customerOrder.setDeliveryStatus(CONSTANT.CustomerOrderStatus.ORDER_NOT_DELIVERY.getCode());
        customerOrder.setUpdateTime(LocalDateTime.now());
        corderMapper.updateById(customerOrder);
        return UniformResponse.createForSuccessMessage(ResponseCode.SUCCESS.getDescription());
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<String> orderReject(Long orderId, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        CustomerOrder customerOrder = corderMapper.selectById(orderId);
        customerOrder.setDeliveryStatus(CONSTANT.CustomerOrderStatus.ORDER_REJECT.getCode());
        customerOrder.setOrderState(CONSTANT.CustomerOrderStatus.CANCEL_ORDER.getCode());
        customerOrder.setUpdateTime(LocalDateTime.now());
        if(customerOrder.getOrderState() == CONSTANT.CustomerOrderStatus.PAID_UNCONFIRMED.getCode()){
            Account upAccount = accountMapper.selectById(account.getUserId());
            upAccount.setBalance(upAccount.getBalance() + customerOrder.getTotalPrice());
            upAccount.setUpdateTime(LocalDateTime.now());
            accountMapper.updateById(upAccount);
        }
        corderMapper.updateById(customerOrder);
        return UniformResponse.createForSuccessMessage(ResponseCode.SUCCESS.getDescription());
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<String> customerOrderCancel(Long orderId, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        CustomerOrder customerOrder = corderMapper.selectById(orderId);
        if(customerOrder.getOrderState() > CONSTANT.CustomerOrderStatus.PAID_UNCONFIRMED.getCode() ||
        customerOrder.getDeliveryStatus() == CONSTANT.CustomerOrderStatus.ORDER_DELIVERY.getCode()){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ORDER_CANNOT_CANCEL.getCode(), ResponseCode.ORDER_CANNOT_CANCEL.getDescription());
        }
        if(customerOrder.getOrderState() == CONSTANT.CustomerOrderStatus.PAID_UNCONFIRMED.getCode()){
            Account upAccount = accountMapper.selectById(account.getUserId());
            upAccount.setBalance(upAccount.getBalance() + customerOrder.getTotalPrice());
            upAccount.setUpdateTime(LocalDateTime.now());
            accountMapper.updateById(upAccount);
        }
        customerOrder.setOrderState(CONSTANT.CustomerOrderStatus.CANCEL_ORDER.getCode());
        customerOrder.setUpdateTime(LocalDateTime.now());
        corderMapper.updateById(customerOrder);
        return UniformResponse.createForSuccessMessage(ResponseCode.SUCCESS.getDescription());
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<CustomerOrderVO> getCustomerOrderDetail(Long orderId, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        CustomerOrder customerOrder = corderMapper.selectOne(
                Wrappers.<CustomerOrder>query().eq("order_id", orderId));
        if(customerOrder == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ORDER_NOT_EXIST.getCode(), ResponseCode.ORDER_NOT_EXIST.getDescription());
        }
        CustomerOrderVO customerOrderVO = this.entityToVO(customerOrder);
        return UniformResponse.createForSuccess(
                ResponseCode.SUCCESS.getDescription(), customerOrderVO);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public UniformResponse<CustomerOrderListVO> getCustomerOrderList(Long orderId, String keyword, int pageSize,
                                                                     int pageNum, Integer orderSource, Integer orderState,
                                                                     Integer deliveryStatus, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }

        Page<CustomerOrder> result = new Page<>();
        result.setCurrent(pageNum);
        result.setSize(pageSize);

        QueryWrapper<CustomerOrder> queryWrapper = new QueryWrapper<>();
        //增加订单id查询
        if(orderId != null){
            queryWrapper.eq("order_id", orderId);
        }
        //增加订单对象查询
        if(account.getRole() != CONSTANT.Role.ADMIN){
            queryWrapper.eq("user_id", account.getUserId());
        }
        //增加关键字查询
        if(StringUtils.isNotBlank(keyword)){
            keyword = new StringBuilder().append("%").append(keyword).append("%").toString();
            queryWrapper.like("order_name", keyword);
        }
        //增加订单来源查询
        if(orderSource != CONSTANT.CommoditySource.ALL_SALE.getCode()){
            queryWrapper.eq("order_source", orderSource);
        }
        //增加订单状态查询
        if(orderState != -1){
            queryWrapper.eq("order_state", orderState);
        }
        //增加发货状态查询
        if(deliveryStatus != -1){
            queryWrapper.eq("delivery_status", deliveryStatus);
        }

        result = corderMapper.selectPage(result, queryWrapper);
        CustomerOrderListVO customerOrderListVO = this.pageToVO(result);
        return UniformResponse.createForSuccess(
                ResponseCode.SUCCESS.getDescription(), customerOrderListVO);
    }


    @Override
    public UniformResponse<AlipayVO> tradePrecreate(Long orderId, Account account) {
        if(account == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.USER_NOT_LOGIN.getCode(), ResponseCode.USER_NOT_LOGIN.getDescription());
        }
        CustomerOrder customerOrder = corderMapper.selectById(orderId);
        if(customerOrder == null){
            return UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ORDER_NOT_EXIST.getCode(), ResponseCode.ORDER_NOT_EXIST.getDescription());
        }
        Integer merchantId = customerOrder.getMerchantId();
        Account merchant = accountMapper.selectById(merchantId);
        AlipayUtil alipayUtil = new AlipayUtil();
        AlipayF2FPrecreateResult result = alipayUtil.test_trade_precreate(customerOrder, merchant);
        if(result.getTradeStatus() != TradeStatus.SUCCESS){
            UniformResponse.createForErrorCodeMessage(
                    ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDescription());
        }
        AlipayVO alipayVO = new AlipayVO();
        alipayVO.setMsg(result.getResponse().getMsg());
        alipayVO.setQrCode(result.getResponse().getQrCode());
        return UniformResponse.createForSuccess(ResponseCode.SUCCESS.getDescription(), alipayVO);
    }

    private CustomerOrderVO entityToVO(CustomerOrder customerOrder){
        CustomerOrderVO customerOrderVO = new CustomerOrderVO();
        customerOrderVO.setOrderId(customerOrder.getOrderId());
        customerOrderVO.setOrderName(customerOrder.getOrderName());
        customerOrderVO.setItemId(customerOrder.getItemId());
        customerOrderVO.setItemName(customerOrder.getItemName());
        customerOrderVO.setItemNumber(customerOrder.getItemNumber());
        customerOrderVO.setUnitPrice(customerOrder.getUnitPrice());
        customerOrderVO.setTotalPrice(customerOrder.getTotalPrice());
        customerOrderVO.setOrderSource(customerOrder.getOrderSource());
        customerOrderVO.setPayment(customerOrder.getPayment());
        customerOrderVO.setOrderState(customerOrder.getOrderState());
        customerOrderVO.setDeliveryStatus(customerOrder.getDeliveryStatus());
        customerOrderVO.setCAddress(customerOrder.getCAddress());
        customerOrderVO.setCPhone(customerOrder.getCPhone());
        customerOrderVO.setMerchantId(customerOrder.getMerchantId());
        customerOrderVO.setMAddress(customerOrder.getMAddress());
        customerOrderVO.setMPhone(customerOrder.getMPhone());

        //新增属性
        customerOrderVO.setCreateTime(DateUtil.localDateTimeToString(customerOrder.getCreateTime()));
        customerOrderVO.setUpdateTime(DateUtil.localDateTimeToString(customerOrder.getUpdateTime()));
        if(customerOrder.getSendTime() != null){
            customerOrderVO.setSendTime(DateUtil.localDateTimeToString(customerOrder.getSendTime()));
        }
        if(customerOrder.getEndTime() != null){
            customerOrderVO.setEndTime(DateUtil.localDateTimeToString(customerOrder.getEndTime()));
        }
        //添加图片
        Commodity commodity = commodityMapper.selectOne(
                Wrappers.<Commodity>query().eq("item_id", customerOrder.getItemId()));
        if(commodity != null){
            customerOrderVO.setImg(commodity.getImage());
        }else{
            customerOrderVO.setImg("item.jpg");
        }
        customerOrderVO.setImgHost(PropertiesUtil.getProperty("image.server.url"));
        return customerOrderVO;
    }

    private CustomerOrderListVO pageToVO(Page<CustomerOrder> result){
        CustomerOrderListVO customerOrderListVO = new CustomerOrderListVO();
        customerOrderListVO.setPageNum(result.getCurrent());
        customerOrderListVO.setPageSize(result.getSize());
        customerOrderListVO.setStartRow(1);
        customerOrderListVO.setEndRow(result.getPages());
        customerOrderListVO.setTotal(result.getTotal());
        customerOrderListVO.setPages(result.getPages());
        List<CustomerOrder> customerOrderList = result.getRecords();
        List<CustomerOrderVO> customerOrderVOList = Lists.newArrayList();
        for(CustomerOrder customerOrder: customerOrderList){
            customerOrderVOList.add(this.entityToVO(customerOrder));
        }
        customerOrderListVO.setCustomerOrderVOList(customerOrderVOList);
        customerOrderListVO.setFirstPage(1l);
        customerOrderListVO.setPrePage(result.getCurrent() -1);
        customerOrderListVO.setNextPage(result.getCurrent() + 1);
        customerOrderListVO.setIsFirstPage(result.getCurrent() == 1);
        customerOrderListVO.setIsLastPage(result.getCurrent() == result.getPages());
        customerOrderListVO.setHasPreviousPage(result.getCurrent() > 1);
        customerOrderListVO.setHasNextPage(result.getCurrent() < result.getPages());
        customerOrderListVO.setImgHost(PropertiesUtil.getProperty("image.server.url"));
        return customerOrderListVO;
    }
}
